﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:childAction="urn:ChildActionExtensions"
  xmlns:link="urn:LinkExtensions"
  xmlns:mvc="urn:HtmlHelper"
  xmlns:renderPartial="urn:RenderPartialExtensions"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:xs="urn:dummy"
  xmlns:output="urn:output"
  xmlns:urlHelper="urn:UrlHelperExtensions"
  xmlns:form="urn:FormExtensions"
  exclude-result-prefixes="msxsl"
                  xmlns:eval="urn:eval">

  <!-- alias xs prefix -->
  <xsl:namespace-alias result-prefix="xsl" stylesheet-prefix="xs" />
  <xsl:output method="xml" indent="no" omit-xml-declaration="no" cdata-section-elements="script"  />
  <xsl:template match="copyOf">
    <xs:copy-of select="{@select}" />
  </xsl:template>
  <xsl:template match="/">

    <xs:stylesheet version="1.0" exclude-result-prefixes="childAction link mvc renderPartial output urlHelper eval" >
      <xs:namespace-alias result-prefix="#default" stylesheet-prefix="output" />
      <xs:output method="html" indent="no" omit-xml-declaration="no" />
      <xs:strip-space elements="*" />
      <xs:variable name="apos">
        <xs:text>'</xs:text>
      </xs:variable>
      <xs:template match="/">
        <xsl:apply-templates select="*" />
      </xs:template>
      <!-- dumps the path to the context -->
      <xs:template name="callStack">
        <xs:param name="context" />
        <xs:if test="$context/..">
          <xs:call-template name="callStack">
            <xs:with-param name="context" select="$context/.." />
          </xs:call-template>
          <xs:text>/</xs:text>
        </xs:if>
        <xs:choose>
          <xs:when test="$context/../@*[generate-id(.)=generate-id($context)]">
            <xs:value-of select="'@'" />
            <xs:value-of select="name($context)" />
          </xs:when>
          <xs:otherwise>
            <xs:value-of select="name($context)" />
            <xs:if test="count($context/@*) &gt; 0">
              <xs:text>[</xs:text>
              <xs:for-each select="$context/@*">
                <xs:value-of select="concat('@',name(),'=',$apos,.,$apos)" disable-output-escaping="yes"/>
                <xs:if test="not(last())"> and </xs:if>
              </xs:for-each>
              <xs:text>]</xs:text>
            </xs:if>
          </xs:otherwise>
        </xs:choose>
      </xs:template>
    </xs:stylesheet>
  </xsl:template>
</xsl:stylesheet>